package com.yxhl.zoume.core.func.map.presenter.location;

import android.content.Context;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.yxhl.zoume.common.presenter.IPresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.specialcar.presenter.ISearchPOIPresenter;
import com.yxhl.zoume.core.specialcar.view.SpecialCarStationMapView;

import java.util.ArrayList;

import javax.inject.Inject;

/**
 * Created by sugarya on 16/4/19.
 */
public class LocationMapPresenter implements IPresenter, ISearchPOIPresenter {

    private static final String TAG = "SpecialMapPresenter";

    private SpecialCarStationMapView mSpecialCarStationMapView;

    @Inject
    public LocationMapPresenter() {
    }

    @Override
    public void doSearchPOIByKeyWord(Context context, String keyWord, int currentPage, String searchCity) {

    }

    @Override
    public void doSearchPOINearBy(Context context, int currentPage, String searchCity, LatLonPoint centerPoint) {
        // 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
        PoiSearch.Query query = new PoiSearch.Query("", "", searchCity);
        query.setPageSize(SEARCH_PAGE_NUM);
        // 设置查第一页
        query.setPageNum(currentPage);

        PoiSearch poiSearch = new PoiSearch(context, query);
        poiSearch.setBound(new PoiSearch.SearchBound(centerPoint, MAP_SEARCH_POI_RADIUS));
        poiSearch.setOnPoiSearchListener(this);
        poiSearch.searchPOIAsyn();
    }


    @Override
    public void onPoiSearched(PoiResult poiResult, int requestCode) {
        if (requestCode == 1000) {
            ArrayList<PoiItem> poiItems = poiResult.getPois();
            if (poiItems != null) {
                mSpecialCarStationMapView.renderPOISearchResult(poiItems);
            } else {
                mSpecialCarStationMapView.renderPOISearchOnFailure();
            }

        }
    }

    @Override
    public void onPoiItemSearched(PoiItem poiItem, int i) {

    }


    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void attachView(BaseView view) {
        if (view != null) {
            if (view instanceof SpecialCarStationMapView) {
                mSpecialCarStationMapView = (SpecialCarStationMapView) view;
            }
        }
    }


}
